<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\Redis\Redis;
use Hyperf\Redis\RedisFactory;
use Hyperf\Utils\ApplicationContext;

/**
 * @AutoController()
 */
class IndexController extends AbstractController
{

    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();

        return [
            'method' => $method,
            'message' => "Hello {$user}."
        ];
    }

    public function getRedis()
    {
        $container = ApplicationContext::getContainer();
        $redis = $container->get(RedisFactory::class)->get('db1');
        $redis->setex('a',120,'我是中国人');
        return [
            'redis' => $redis->get('a')
        ];
    }

    /**
     * @GetMapping(path="mysql")
     */
    public function getMysql()
    {
        return [
            'code'=>1
        ];
    }
}
